<?php
/*
 *  @author Nicolas Genevaux
 * (c)nige 2008
 */
	$IDMATIERE = $_POST['matiere'];
	include($RACINE.'inc/var.points.php');
	include_once($RACINE.'inc/fct.utils.php');
	include_once($RACINE.'inc/sql.matiere.php');
	include_once($RACINE.'inc/sql.inscritmatiere.php');
	include_once($RACINE.'inc/sql.matiereinscritmatiere.php');
	include_once($RACINE.'inc/var.matiere.php');
	if($_POST['matiere'] == -1) {
		redirect($PAGE_ACCUEIL_INSCRIT);
	}
	else {
		$coutInscription = $INSCRIPTION;
		$res = doSQL($MATIERE_SELECT_ID,array(0=>$IDMATIERE));
		$nomMatiere = $res['matiere'];
		$res = doSQL($MATIEREINSCRITMATIERE_SELECT_CPT,array(0=>$_SESSION['ID_CONECT']));
		$totalMatiere = $res['total'];
		$res = doSQL($MATIEREINSCRITMATIERE_SELECT_INS,array(0=>$_SESSION['ID_CONECT'],1=>$IDMATIERE));
		$dejaInscrit = $res['total'];
		if($INSCRIT->points < $coutInscription) {
			include($RACINE.'texte/matiere_inscriptionmatiereno.php');
		}
		else if($totalMatiere > $NOMBREMAXMATIERE) {
			include($RACINE.'texte/matiere_inscriptionmatieretoom.php');
		}
		else if($dejaInscrit > 0) {
			include($RACINE.'texte/matiere_inscriptionmatieredeja.php');
		}
		else {
			if($_POST['accept']==1) {
				doSQL($INSCRITMATIERE_INSERT,array(0=>$_SESSION['ID_CONECT'],1=>$IDMATIERE));
				doSQL($INSCRIT_POINTS,array(0=>$_SESSION['ID_CONECT'],1=>"(".-1*$INSCRIPTION.")"));
				redirect($PAGE_ACCUEIL_INSCRIT);
			}
			else if($_POST['accept']==2) {
				redirect($PAGE_ACCUEIL_INSCRIT);
			}
			else {
				include($RACINE.'texte/matiere_inscriptionmatiereyes.php');
			}
		}
	}
?>
